package com.fengyi.library.config;

import com.fengyi.library.service.impl.LoanStatusUpdater;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * 应用程序启动监听器
 * 在应用启动完成后执行初始化操作，如更新借阅状态
 */
@Component
public class ApplicationStartupListener implements ApplicationListener<ApplicationReadyEvent> {

    private final LoanStatusUpdater loanStatusUpdater;

    @Autowired
    public ApplicationStartupListener(LoanStatusUpdater loanStatusUpdater) {
        this.loanStatusUpdater = loanStatusUpdater;
    }

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        // 应用启动时执行一次借阅状态更新
        loanStatusUpdater.updateLoanStatusNow();
        System.out.println("已完成借阅状态初始化更新");
    }
}
